#include "main.h"
#include "z80.h"

void version_number(Z80EX_CONTEXT *cpu, Z80EX_BYTE c, Z80EX_WORD de);

int bdos_call(Z80EX_CONTEXT *cpu, Z80EX_BYTE c, Z80EX_WORD de)
{
	switch(c)
	{
		case 0x00: quit(); break;
		case 0x01: console_input(cpu, c, de); break;
		case 0x02: console_output(cpu, c, de); break;
		case 0x06: direct_console_io(cpu, c, de); break;
		case 0x09: output_string(cpu, c, de); break;
		case 0x0A: buffered_console_input(cpu, c, de); break;
		case 0x0B: console_status(cpu, c, de); break;
		case 0x0C: version_number(cpu, c, de); break;
		case 0x0D: reset_discs(cpu, c, de); break;
		case 0x0E: select_disc(cpu, c, de); break;
		case 0x0F: open_file(cpu, c, de); break;
		case 0x10: close_file(cpu, c, de); break;
		case 0x11: search_for_first(cpu, c, de); break;
		case 0x12: search_for_next(cpu, c, de); break;
		case 0x13: delete_file(cpu, c, de); break;
		case 0x14: read_next_record(cpu, c, de); break;
		case 0x15: write_next_record(cpu, c, de); break;
		case 0x16: create_file(cpu, c, de); break;
		case 0x17: rename_file(cpu, c, de); break;
		case 0x18: return_bitmap_of_logged_in_drives(cpu, c, de); break;
		case 0x19: return_current_drive(cpu, c, de); break;
		case 0x1A: set_dma_address(cpu, c, de); break;
		default:printf("BDOS call with %04x\n", c);
	}
	
	return 1;
}

/* Entered with C=0Ch. Returns B=H=system type, A=L=version number. */
void version_number(Z80EX_CONTEXT *cpu, Z80EX_BYTE c, Z80EX_WORD de)
{
	Z80EX_BYTE system_type = 0; // 8080, plain CP/M
	Z80EX_BYTE version = 0x22; // CP/M v 2.2
	
	z80_set_high(cpu, regBC, system_type);
	z80_set_high(cpu, regHL, system_type);
	z80_set_high(cpu, regAF, version);
	z80_set_low(cpu, regHL, version);
}
